package com.iwdnb.gkgz.application.strategy;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import cn.hutool.core.date.DateUtil;
import com.iwdnb.gkgz.application.model.request.AddStrategyTradeStockDataRequest;
import com.iwdnb.gkgz.common.model.dto.StockDayData;
import com.iwdnb.gkgz.common.model.dto.StockRangeDTO;
import com.iwdnb.gkgz.common.model.dto.StrategyTradeDTO;
import com.iwdnb.gkgz.common.quota.BollingerBands;
import com.iwdnb.gkgz.common.quota.CCIIndicator;
import com.iwdnb.gkgz.common.quota.MacdIndicator;
import com.iwdnb.gkgz.common.quota.MovingAverage;
import com.iwdnb.gkgz.common.quota.RSIIndicator;
import com.iwdnb.gkgz.common.quota.WRIndicator;
import com.iwdnb.gkgz.common.utils.BigDecimalUtils;
import com.iwdnb.gkgz.common.utils.DateUtils;
import com.iwdnb.gkgz.common.utils.StockRangeUtils;
import com.iwdnb.gkgz.common.utils.StockUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import static com.iwdnb.gkgz.common.utils.StockUtils.getAveragePrice;

/**
 * 布林线跌穿下轨策略
 */
@Service
@Slf4j
public class BollingDownStockBackValidateService extends CommmonStockBackValidateService {

    private static final String STATEGY_CODE = "bollingDown";

    /**
     * 高价日期后10天的毫秒数
     */
    private static final Long HIGH_DAY_PERIOD_MILLIONS_SECOND = 10 * 86400 * 1000L;
    private BigDecimal pointFive = new BigDecimal(0.5);
    private static final BigDecimal pointZeroFive = new BigDecimal(0.05);
    private static final BigDecimal fuHundredFifty = new BigDecimal(-150);
    private static final BigDecimal fuNinePointFive = new BigDecimal(-9.5);
    private static final BigDecimal fuFourPointEight = new BigDecimal(-4.8);
    private static final BigDecimal fuFivePointTwo = new BigDecimal(-5.2);

    int sixtyPeriod = 60;

    @Override
    public List<StrategyTradeDTO> queryBackValidateDateList(String code, String strategy,
        List<StockDayData> stockDayDataList, AddStrategyTradeStockDataRequest request) {
        MacdIndicator.calculateMACD(stockDayDataList);
        BollingerBands.calculateBollingerBands(stockDayDataList);
        RSIIndicator.calculateRSI(stockDayDataList);
        CCIIndicator.calculateCCI(stockDayDataList);
        WRIndicator.calculateWR(stockDayDataList);
        MovingAverage.calculateEMA(stockDayDataList, sixtyPeriod);
        List<StockRangeDTO> stockRangeDTOList = StockRangeUtils.calculateStockRange(stockDayDataList);

        List<String> dateList = new ArrayList<>();
        List<StrategyTradeDTO> strategyTradeDTOList = new ArrayList<>();
        Set<String> downDateSet = new HashSet<>();
        for (int i = 0; i < stockDayDataList.size() - 1; i++) {
            if (i < 700) {
                continue;
            }
            StockDayData data = stockDayDataList.get(i);
            String date = data.getDate();
            BigDecimal closePrice = data.getClosePrice();
            BigDecimal rate = data.getRate();
            StockDayData beforeThreeData = stockDayDataList.get(i - 3);
            StockDayData beforeTwoData = stockDayDataList.get(i - 2);
            StockDayData beforeOneData = stockDayDataList.get(i - 1);
            //连续3天股价都下跌
            if (BigDecimalUtils.isGe(beforeTwoData.getRate(), BigDecimal.ZERO)
                || BigDecimalUtils.isGe(beforeOneData.getRate(), BigDecimal.ZERO)
                || BigDecimalUtils.isGt(data.getRate(), BigDecimal.ZERO)) {
                continue;
            }
            ////跌超过9.5，当做跌停，跳过
            //if (BigDecimalUtils.isLe(data.getRate(), fuNinePointFive)) {
            //    continue;
            //}
            //忽略ST跌停
            if (BigDecimalUtils.eq(closePrice, data.getOpenPrice())) {
                if (BigDecimalUtils.isLe(rate, fuFourPointEight)
                    && BigDecimalUtils.isGe(rate, fuFivePointTwo)) {
                    continue;
                }
            }
            //计算3天跌了多少
            BigDecimal beforeThreeDayRate = BigDecimalUtils.subStractAndDividePrecent(beforeThreeData.getClosePrice(),
                data.getClosePrice());
            //前面10天跌了大多数时间
            boolean multiDownFlag = isMultiDown(stockDayDataList, data);
            //半年前有波段低点,与当前价格10%以内
            boolean earlyLowFlag = isEarlyLow(stockDayDataList, stockRangeDTOList, data);
            //if(!multiDownFlag && !earlyLowFlag){
            //    continue;
            //}

            BigDecimal beforeTwoLowBand = beforeTwoData.getBollingerBand().getLowBand();
            BigDecimal beforeOneLowBand = beforeOneData.getBollingerBand().getLowBand();
            BigDecimal lowBand = data.getBollingerBand().getLowBand();
            //连续3天股价都在布林线下轨之下
            if (BigDecimalUtils.isGe(beforeTwoData.getClosePrice(), beforeTwoLowBand)
                || BigDecimalUtils.isGe(beforeOneData.getClosePrice(), beforeOneLowBand)
                || BigDecimalUtils.isGt(data.getClosePrice(), lowBand)) {
                continue;
            }
            downDateSet.add(beforeTwoData.getDate());
            downDateSet.add(beforeOneData.getDate());
            downDateSet.add(date);
            //获取连续跌入下轨的时间
            List<StockDayData> nextDayDatas = StockUtils.getStockDayDataListAfterDate(stockDayDataList, date, 10);
            int downDateCount = getNextBollingDownDateCount(nextDayDatas, downDateSet);
            StockDayData lastDownData = downDateCount > 0 ? nextDayDatas.get(downDateCount - 1) : data;
            downDateCount = downDateCount + 3;
            //获取股价最小日期
            int minDateIndex = getMinDate(data, nextDayDatas);
            BigDecimal afterOneRate = nextDayDatas.size() >= 1 ? nextDayDatas.get(0).getRate() : null;
            BigDecimal afterTwoRate = nextDayDatas.size() >= 2 ? nextDayDatas.get(1).getRate() : null;
            BigDecimal afterThreeRate = nextDayDatas.size() >= 3 ? nextDayDatas.get(2).getRate() : null;
            //rsi值小于15
            BigDecimal rsi = StockUtils.getStockQuota(data, RSIIndicator.QUOTA_NAME);
            if (BigDecimalUtils.isGe(rsi, fourty)) {
                continue;
            }
            //cci值小于-150
            BigDecimal cci = StockUtils.getStockQuota(data, CCIIndicator.QUOTA_NAME);
            if (BigDecimalUtils.isGe(cci, fuHundredFifty)) {
                continue;
            }
            //wr小于90
            BigDecimal wr = StockUtils.getStockQuota(data, WRIndicator.QUOTA_NAME);
            if (BigDecimalUtils.isLe(wr, seventy)) {
                continue;
            }
            String buyDate = data.getDate();
            if (!dateList.contains(buyDate)) {
                dateList.add(buyDate);
                StrategyTradeDTO strategyTradeDTO = new StrategyTradeDTO();
                strategyTradeDTO.setCode(code);
                strategyTradeDTO.setUuid(STATEGY_CODE);
                strategyTradeDTO.setBuyDate(DateUtil.parseDate(buyDate));
                strategyTradeDTO.setBuyPrice(data.getClosePrice());
                strategyTradeDTO.setBuyMinPrice(data.getMinPrice());
                strategyTradeDTO.setStatus("buy");
                BigDecimal limitSellPrice = data.getMinPrice();
                strategyTradeDTO.setLimitSellPrice(limitSellPrice);
                strategyTradeDTO.setSignalPrice(data.getClosePrice());
                strategyTradeDTO.setBuySignalRate(
                    BigDecimalUtils.subStractAndDividePrecent(strategyTradeDTO.getSignalPrice(),
                        strategyTradeDTO.getBuyPrice()));
                strategyTradeDTO.setBuySignalMinRate(
                    BigDecimalUtils.subStractAndDividePrecent(strategyTradeDTO.getSignalPrice(),
                        strategyTradeDTO.getBuyMinPrice()));
                strategyTradeDTO.setV1(rsi);
                strategyTradeDTO.setV2(cci);
                strategyTradeDTO.setV3(wr);
                strategyTradeDTO.setV4(multiDownFlag ? one : BigDecimal.ZERO);
                strategyTradeDTO.setV5(earlyLowFlag ? one : BigDecimal.ZERO);
                strategyTradeDTO.setV6(new BigDecimal(downDateCount));
                strategyTradeDTO.setV7(new BigDecimal(minDateIndex));
                strategyTradeDTO.setV8(beforeThreeDayRate);
                strategyTradeDTO.setV9(
                    BigDecimalUtils.subStractAndDividePrecent(data.getClosePrice(), lastDownData.getClosePrice()));
                strategyTradeDTO.setV10(beforeTwoData.getRate());
                strategyTradeDTO.setV11(beforeOneData.getRate());
                strategyTradeDTO.setV12(data.getRate());
                strategyTradeDTO.setV13(afterOneRate);
                strategyTradeDTO.setV14(afterTwoRate);
                strategyTradeDTO.setV15(afterThreeRate);
                strategyTradeDTOList.add(strategyTradeDTO);

                //BigDecimal profit = caculateAfterDaysProfit(backDayData.getDate(), stockDayDataList, 5);
                //log.debug("{}-{}买入,未来5天最高收益为:{}", code, buyDate, profit);
            }

        }
        return strategyTradeDTOList;
    }

    private boolean isEarlyLow(List<StockDayData> stockDayDataList,
        List<StockRangeDTO> stockRangeDTOList, StockDayData data) {
        String date = data.getDate();
        Date endDate = DateUtil.parseDate(date);
        Date beginDate = DateUtil.offsetDay(endDate, -450);

        stockRangeDTOList = stockRangeDTOList.stream().filter(t -> DateUtil.parseDate(t.getBeginDate()).after(beginDate)
            || DateUtil.parseDate(t.getEndDate()).before( endDate)).collect(Collectors.toList());
        StockRangeDTO stockRangeDTO = StockRangeUtils.getMatchLowRangeByDateRange(data, stockRangeDTOList);
        if (Objects.isNull(stockRangeDTO)) {
            return false;
        }
        String lowDate = stockRangeDTO.getBeginDate();
        stockDayDataList = StockUtils.getStockDayDataListByDateRange(stockDayDataList, lowDate, date);
        int dayCount = stockDayDataList.size();
        //半年之内,4月到8月之间
        return dayCount > 80 && dayCount < 170;
    }

    private boolean isMultiDown(List<StockDayData> stockDayDataList, StockDayData data) {
        stockDayDataList = StockUtils.getStockDayDataListBeforeDate(stockDayDataList, data.getDate(), 10);
        int downCount = 0;
        for (StockDayData stockDayData : stockDayDataList) {
            if (BigDecimalUtils.isLe(stockDayData.getRate(), BigDecimal.ZERO)) {
                downCount++;
            }
        }
        return downCount > 7;
    }

    private int getMinDate(StockDayData data, List<StockDayData> nextDayDatas) {
        BigDecimal minPrice = data.getMinPrice();
        int index = 0;
        for (int i = 0; i < nextDayDatas.size(); i++) {
            StockDayData nextData = nextDayDatas.get(i);
            if (BigDecimalUtils.isLt(nextData.getMinPrice(), minPrice)) {
                index = i + 1;
            }
        }
        return index;
    }

    private int getNextBollingDownDateCount(List<StockDayData> nextDatas, Set<String> downDateSet) {
        int downCount = 0;
        for (int i = 0; i < nextDatas.size(); i++) {
            StockDayData data = nextDatas.get(i);
            if (BigDecimalUtils.isGe(data.getClosePrice(), data.getBollingerBand().getLowBand())) {
                break;
            }
            downCount++;
            downDateSet.add(data.getDate());
        }

        return downCount;
    }

    private boolean isInHighDate(String dateStr, List<Date> highDateList) {
        Date date = DateUtil.parseDate(dateStr);
        for (Date highDate : highDateList) {
            if (date.before(highDate)) {
                continue;
            }
            if (date.getTime() - highDate.getTime() < HIGH_DAY_PERIOD_MILLIONS_SECOND) {
                return true;
            }
        }
        return false;
    }

    @Override
    public void doBackValidate(String code, String strategy, List<StockDayData> stockDayDataList,
        List<StrategyTradeDTO> strategyTradeDTOList) {
        List<String> dateList = strategyTradeDTOList.stream().map(o -> DateUtil.formatDate(o.getBuyDate()))
            .collect(Collectors.toList());
        Date latestEndDate = strategyTradeDTOList.get(0).getBuyDate();
        latestEndDate = DateUtil.offsetDay(latestEndDate, -1);
        for (StrategyTradeDTO strategyTradeDTO : strategyTradeDTOList) {
            Date d = strategyTradeDTO.getBuyDate();
            if (DateUtils.beforeOrEquals(d, latestEndDate)) {
                log.debug("{}-{}在上一个周期内,忽略", code, d);
                continue;
            }
            getTradeInfo(code, stockDayDataList, strategyTradeDTO);
            latestEndDate = strategyTradeDTO.getSellDate();
        }
    }

    private void getTradeInfo(String code, List<StockDayData> stockDayDataList, StrategyTradeDTO strategyTradeDTO) {
        String date = DateUtil.formatDate(strategyTradeDTO.getBuyDate());
        //log.debug("{}-{}>>>>>股票信息:{}", code, date, strategyTradeDTO.getSummary());
        StockDayData buyDayData = StockUtils.getStockDayData(stockDayDataList, date);
        BigDecimal buyPrice = buyDayData.getClosePrice();
        int size = 15;
        List<StockDayData> subList = StockUtils.getStockDayDataListAfterDate(stockDayDataList, date, size);
        if (CollectionUtils.isEmpty(subList) || subList.size() < size) {
            return;
        }
        BigDecimal closeRate = null;
        String sellDate = null;
        String info = "";
        BigDecimal sellPrice = null;
        BigDecimal rate = closeRate;
        int holdIndex = 0;
        BigDecimal rangeMaxPrice = strategyTradeDTO.getBuyPrice();
        BigDecimal rangeMaxRate = BigDecimal.ZERO;
        BigDecimal rangeCloseMaxPrice = strategyTradeDTO.getBuyPrice();
        BigDecimal rangeCloseMaxRate = BigDecimal.ZERO;
        BigDecimal minPrice = strategyTradeDTO.getRealtimePrice();
        BigDecimal fuTwoPointThree = new BigDecimal(-2.5);
        BigDecimal fuFive = new BigDecimal(-5);
        for (int i = 0; i < size; i++) {
            StockDayData data = subList.get(i);
            StockDayData yesterdayDayData = i == 0 ? data : subList.get(i - 1);
            BigDecimal closePrice = data.getClosePrice();
            closeRate = BigDecimalUtils.subStractAndDividePrecent(closePrice, buyPrice);
            sellDate = data.getDate();
            sellPrice = data.getClosePrice();
            holdIndex = i;
            rangeMaxPrice = BigDecimalUtils.isGt(data.getMaxPrice(), rangeMaxPrice) ? data.getMaxPrice()
                : rangeMaxPrice;
            rangeMaxRate = BigDecimalUtils.subStractAndDividePrecent(rangeMaxPrice, buyPrice);
            rangeCloseMaxPrice = BigDecimalUtils.isGt(data.getClosePrice(), rangeCloseMaxPrice) ? data.getClosePrice()
                : rangeCloseMaxPrice;
            rangeCloseMaxRate = BigDecimalUtils.subStractAndDividePrecent(rangeCloseMaxPrice, buyPrice);
            BigDecimal realtimeRate = BigDecimalUtils.subStractAndDividePrecent(data.getClosePrice(), buyPrice);
            BigDecimal upRange = data.getMaxPrice().subtract(buyPrice);
            BigDecimal upRate = BigDecimalUtils.divideToPrecent(upRange, buyPrice);
            BigDecimal openRange = data.getOpenPrice().subtract(buyPrice);
            BigDecimal openRate = BigDecimalUtils.divideToPrecent(openRange, buyPrice);
            rate = closeRate;
            String sellInfo = "收盘价卖出";

            if (BigDecimalUtils.isGe(realtimeRate, new BigDecimal(120))) {
                Integer yesterdayTradeNumTenTimes = yesterdayDayData.getTradeNum() * 10;
                if (data.getTradeNum() >= yesterdayTradeNumTenTimes) {
                    sellInfo = "出现十倍信号量,止盈";
                    log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo,
                        rate, openRate, closeRate, upRate);
                    info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                        + ",最高点收益=" + upRate;
                    break;
                }
            }
            //首日跌2.5个点以上，直接卖出
            if (i == 0 && BigDecimalUtils.isLt(data.getRate(), fuTwoPointThree)) {
                sellInfo = "首日跌超过2.5个点,卖出";
                log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                    openRate, closeRate, upRate);
                info += "第" + (i + 1) + "天-" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }
            //跌5个点，跑路
            if (BigDecimalUtils.isLt(closeRate, fuFive)) {
                sellInfo = "跌过5个点,止损";
                log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                    openRate, closeRate, upRate);
                info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }

            //连跌3天，如果前面是涨停板就等跌破涨停板低点卖出
            if (i >= 2) {
                StockDayData beforeTwoData = subList.get(i - 2);
                StockDayData beforeOneData = subList.get(i - 1);
                if (BigDecimalUtils.isLe(data.getRate(), BigDecimal.ZERO) && BigDecimalUtils.isLe(
                    beforeOneData.getRate(), BigDecimal.ZERO) && BigDecimalUtils.isLe(beforeTwoData.getRate(),
                    BigDecimal.ZERO)) {
                    sellInfo = "连跌3天,止损";
                    log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo,
                        rate, openRate, closeRate, upRate);
                    info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                        + ",最高点收益=" + upRate;
                    break;
                }
            }

            //涨过100个点，直接卖出
            if (BigDecimalUtils.isGe(closeRate, new BigDecimal(100))) {
                sellInfo = "涨过80个点,卖掉";
                log.debug("{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", code, data.getDate(), sellInfo, rate, openRate,
                    closeRate, upRate);
                info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }
            ////5天内涨过35个点
            //if (i <= 4 && !StockUtils.isLimitUp(data) && BigDecimalUtils.isGe(closeRate, new BigDecimal(35))) {
            //    sellInfo = "4天涨过30个点,卖掉";
            //    log.debug("{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", code, data.getDate(), sellInfo, rate, openRate,
            //        closeRate, upRate);
            //    info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
            //        + ",最高点收益=" + upRate;
            //    break;
            //}
            //5天还没涨过5个点
            if (i == 5 && BigDecimalUtils.isLt(closeRate, new BigDecimal(3))) {
                sellInfo = "6天没涨过3个点,卖掉";
                log.debug("{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", code, data.getDate(), sellInfo, rate, openRate,
                    closeRate, upRate);
                info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }

            //20个点以上，回落到10个点
            if (BigDecimalUtils.isGe(rangeCloseMaxRate, new BigDecimal(20)) && BigDecimalUtils.isLe(
                realtimeRate.multiply(new BigDecimal(2)), rangeCloseMaxRate)) {
                sellInfo = "20个点以上回落到10个点左右,止盈";
                log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                    openRate, closeRate, upRate);
                info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }
            //冲高回落
            if (BigDecimalUtils.isGe(rangeCloseMaxRate, new BigDecimal(7)) && BigDecimalUtils.isLe(realtimeRate,
                new BigDecimal(3))) {
                sellInfo = "冲高回落,卖出";
                log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                    openRate, closeRate, upRate);
                info += "第" + (i + 1) + "天-" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }

            //15日内跌停
            if (i < 15 && StockUtils.isLimitDown(data)) {
                sellInfo = "跌停,卖出";
                log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                    openRate, closeRate, upRate);
                info += "第" + (i + 1) + "天-" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }

            if (i == size - 1) {
                log.debug("第{}天-{}-{}-{}，收益={}，开盘收益={},收盘收益={},最高点收益={}", (i + 1), code, data.getDate(), sellInfo, rate,
                    openRate, closeRate, upRate);
                info += "第" + (i + 1) + "天" + sellInfo + ",收益=" + rate + ",开盘收益=" + openRate + ",收盘收益=" + closeRate
                    + ",最高点收益=" + upRate;
                break;
            }

        }
        strategyTradeDTO.setHoldDay(holdIndex + 1);
        strategyTradeDTO.setSellDate(DateUtil.parseDate(sellDate));
        strategyTradeDTO.setSellPrice(sellPrice);
        strategyTradeDTO.setProfitRate(rate);
        strategyTradeDTO.setRangeMaxPrice(rangeMaxPrice);
        strategyTradeDTO.setRangeMaxRate(BigDecimalUtils.subStractAndDividePrecent(rangeMaxPrice, buyPrice));
        strategyTradeDTO.setStrategyDescription(info);
        strategyTradeDTO.setStatus("sell");
        StockDayData data = subList.get(0);
        strategyTradeDTO.setV16(StockUtils.getStockQuota(data, RSIIndicator.QUOTA_NAME));
        strategyTradeDTO.setV17(StockUtils.getStockQuota(data, CCIIndicator.QUOTA_NAME));
        strategyTradeDTO.setV18(StockUtils.getStockQuota(data, WRIndicator.QUOTA_NAME));

        strategyTradeDTO.setWinFlag(BigDecimalUtils.isGt(rate, BigDecimal.ZERO) ? "y" : "n");
    }

}
